<?php
//定义IN_TG 常量，值为true
    define('IN_TG',true);
//引入文件
    include("includes/common.inc.php");
//销毁Sesssion，重新登录
    _session_destroy();
?>
<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>登录 - 后台管理</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
    <style>
        .login-panel {
            margin-top: 35%;
        }
    </style>
</head>

<body>

<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">Please Sign In</h3>
                </div>
                <div class="panel-body">
                    <form role="form">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" placeholder="Username" name="usernmae" id="admin_user" type="text" autofocus required>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="Password" name="password" id="admin_pwd" type="password" value="" required>
                            </div>
                            <!-- Change this to a button or input when using this as a form -->
                            <a href="#" id="admin_go_login" class="btn btn-lg btn-success btn-block">Login</a>
                        </fieldset>
                    </form>
                </div>
            </div>
            <div class="alert alert-danger alert-dismissable" id="login_warning_alert" style="display: none">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <span id="login_warning"></span>
            </div>
        </div>
    </div>
</div>
<?php include('admin_footer.php');?>
<script>
    //使用jquery 中的ajax 发送用户名和密码到admin_action.php,进行登录验证
    $(function(){
        $("#admin_go_login").click(function(){
            $('#login_warning_alert').hide();
            var admin_user=$("#admin_user").val();
            var admin_pwd=$("#admin_pwd").val();
            $.ajax({
               type:"post",
                url:'admin_action.php',
                data:{admin_user:admin_user,admin_pwd:admin_pwd,type:'admin_go_login'},
                dataType:'json',
                success:function(data)
                {
                    if(data.status==1)
                    {
                        window.location.href='admin_index.php';
                    }
                    else
                    {
                        $("#login_warning").html(data.msg);
                        $('#login_warning_alert').show();
                    }
                },
                error:function()
                {
                    $("#login_warning").html('网络异常');
                    $('#login_warning_alert').show();
                }
            });
        })
    })
</script>